package minimips

import (
	"fmt"
	"dumpwave"
//  	"testbanch"
// 	"os"
// 	"log"
)
 
func imem(
	instructions chan []uint32,
	imem_address chan uint,
	imem_data chan uint){
//  	memory := (testbanch.Instrutions())
	memory :=<- instructions
	
	
	fmt.Println(memory)
// 	memory := [] uint {
// 		0x8c220000, //L: lw  r2,0(r1)
// 		0x8c640000, //   lw  r4,0(r3)
// 		0x00a42020, //   add r4,r5,r4
// 		0x00642824, //   and r5,r3,r4
// 		0xac640000, //   sw  r4,0(r3)
// 		0x00822022, //M: sub r4,r4,r2
// 		0x1080fff9, //   beq r4,r0, L
// 		0x18000005} //   j   M 

	var addr, instr uint
	for {
		addr =<- imem_address
		fmt.Println("[imem] PC <-- FETCH:",addr)
		instr = uint(memory[addr & 0xFF])
		fmt.Printf("[imem] INSTR --> FETCH: 0x%x\n",instr)
		dumpwave.Wave(1,"imem_dataRA")
		dumpwave.Wave(int(instr),"imem_data")
		imem_data <- instr
		dumpwave.Wave(0,"imem_dataRA")
	}
	
}
